﻿CREATE PROCEDURE [audit].[StartTrace]
@TraceID INT
AS
BEGIN
	DECLARE @RC int, @ERROR int
	SET @RC = 0
	SET @ERROR = 0

	EXEC @RC = master.dbo.sp_trace_setstatus @TraceID, 1 --START TRACE FLAG
	SET @ERROR = @@ERROR
	IF(@RC <> 0)	
		BEGIN
			DECLARE @ERROR_MESSAGE nvarchar(512)
			SET @ERROR_MESSAGE = audit.GetTraceReturnCodeValue(@RC)
			RAISERROR(@ERROR_MESSAGE,16,1)
		END
	IF(@ERROR <> 0)
		SET @RC = @ERROR

	IF(@RC = 0)
		PRINT '(Trace started successfully)'

	RETURN(@RC)
END